<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Characteristics
 * This class represents a data access object for the database table 'characteristics'.
 */
class Characteristics {


	private $dao = null;

	private $i = 1;

	/**
	 * associated database field: characteristicId, type: int, is nullable: false
	 */
	private $characteristicId  = 0;

	/**
	 * associated database field: characteristicCode, type: varchar, is nullable: true, character set: utf8, max length: 10
	 */
	private $characteristicCode;

	/**
	 * associated database field: characteristicDescription, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $characteristicDescription;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("Characteristics");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['characteristicId'])) $this->characteristicId = $row['characteristicId'];
		if(isset($row['characteristicCode'])) $this->characteristicCode = $row['characteristicCode'];
		if(isset($row['characteristicDescription'])) $this->characteristicDescription = $row['characteristicDescription'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Characteristics
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'characteristicId: '.(($escapeQuotationMarks===true) ? addslashes($this->characteristicId) : $this->characteristicId).', ';
		$s .= 'characteristicCode: '.(($escapeQuotationMarks===true) ? addslashes($this->characteristicCode) : $this->characteristicCode).', ';
		$s .= 'characteristicDescription: '.(($escapeQuotationMarks===true) ? addslashes($this->characteristicDescription) : $this->characteristicDescription);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Characteristics
	 */
	public function toJSONString(){
		$fieldValues = array ("characteristicId"=>$this->characteristicId, "characteristicCode"=>$this->characteristicCode, "characteristicDescription"=>$this->characteristicDescription);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Characteristics object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"characteristics\">\n";
		$htmlCode .= '	<div class="characteristics_characteristicId">'.(($escapeHTML===true) ? htmlspecialchars($this->characteristicId) : $this->characteristicId)."</div>\n";
		$htmlCode .= '	<div class="characteristics_characteristicCode">'.(($escapeHTML===true) ? htmlspecialchars($this->characteristicCode) : $this->characteristicCode)."</div>\n";
		$htmlCode .= '	<div class="characteristics_characteristicDescription">'.(($escapeHTML===true) ? htmlspecialchars($this->characteristicDescription) : $this->characteristicDescription)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}


	public static function loadAll(){
		$characteristics = new Characteristics();
		$rows = $characteristics->dao->getData("");
		$characteristicss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Characteristics();
			$d->init($rows[$index]);
			array_push($characteristicss,$d);
		}
		return $characteristicss;
	}


	/**
	 * Load the Characteristics uniquely by its primary key.
	 * @param characteristicId the primary key
	 * @return Characteristics Instance of {@link Characteristics}
	 */
	public static function loadUnique($characteristicId){
		$characteristics = new Characteristics();
		$rows = $characteristics->dao->getData("`characteristicId`='$characteristicId'");
		$characteristics->init($rows[0]);
		return $characteristics;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("characteristicId"=>$this->characteristicId, "characteristicCode"=>$this->characteristicCode, "characteristicDescription"=>$this->characteristicDescription);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("characteristicId"=>$this->characteristicId, "characteristicCode"=>$this->characteristicCode, "characteristicDescription"=>$this->characteristicDescription);
		$where = "`characteristicId`='$characteristicId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['characteristicId'])){
			$this->characteristicId = $_POST['characteristicId'];
		}
		if (isset($_POST['characteristicCode'])){
			$this->characteristicCode = $_POST['characteristicCode'];
		}
		if (isset($_POST['characteristicDescription'])){
			$this->characteristicDescription = $_POST['characteristicDescription'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['characteristicId'])){
			$this->characteristicId = $_GET['characteristicId'];
		}
		if (isset($_GET['characteristicCode'])){
			$this->characteristicCode = $_GET['characteristicCode'];
		}
		if (isset($_GET['characteristicDescription'])){
			$this->characteristicDescription = $_GET['characteristicDescription'];
		}
	}


	/**
	 * Returns the value from the database field characteristicId.
	 * In the database the field characteristicId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getCharacteristicId(){
		return $this->characteristicId;
	}


	/**
	 * Set the value from the database field characteristicId.
	 * In the database the field characteristicId is of type int.
	 * The database field is NOT nullable.
	 * @param characteristicId String with the value for the field to be set
	 */
	public function setCharacteristicId($characteristicId){
		$this->characteristicId = $characteristicId;
	}


	/**
	 * Returns the value from the database field characteristicCode.
	 * In the database the field characteristicCode is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getCharacteristicCode(){
		return $this->characteristicCode;
	}


	/**
	 * Set the value from the database field characteristicCode.
	 * In the database the field characteristicCode is of type varchar.
	 * The database field is  nullable.
	 * @param characteristicCode String with the value for the field to be set
	 */
	public function setCharacteristicCode($characteristicCode){
		if(strlen($characteristicCode) > 10) throw new Exception("characteristicCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($characteristicCode)." characters.");
		$this->characteristicCode = $characteristicCode;
	}


	/**
	 * Returns the value from the database field characteristicDescription.
	 * In the database the field characteristicDescription is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getCharacteristicDescription(){
		return $this->characteristicDescription;
	}


	/**
	 * Set the value from the database field characteristicDescription.
	 * In the database the field characteristicDescription is of type varchar.
	 * The database field is  nullable.
	 * @param characteristicDescription String with the value for the field to be set
	 */
	public function setCharacteristicDescription($characteristicDescription){
		if(strlen($characteristicDescription) > 45) throw new Exception("characteristicDescription does not allow strings longer than 45 characters. The submitted string contains ".strlen($characteristicDescription)." characters.");
		$this->characteristicDescription = $characteristicDescription;
	}
}
?>